package com.ysd.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ysd.entity.Students;
import com.ysd.service.StudentsService;
import com.ysd.util.Result;

@RestController
public class StudentsController {
		
	@Autowired
	private StudentsService sService;
	@Resource
	private SimpleDateFormat dateFormat;
	
	@RequestMapping("getStudents")
	public Object getStudents(Students s) {
		s.setPage((s.getPage()-1)*s.getLimit());
		List<Students>	list=sService.getStudent(s);
		
		if (list!=null) {
			int	count=sService.getCount(s);
			return Result.toClient("0", "��ѯ�ɹ�", count, list);
		} else {
			return Result.toClient("1", "��ѯʧ��");
		}	
	}
	//添加
	@RequestMapping("addStus")
	public Object addStus(Students s) {
//		CreateTime=dateFormat.format(new Date());
//		System.out.println(CreateTime);
		int n=sService.addStus(s);
		//s.setCreateTime(CreateTime);
		if (n>0) {
			return Result.toClient("0", "添加成功");
		}
		return Result.toClient("1", "添加失败");
	}
	//删除
	@RequestMapping("deleteStus")
	public Object deleteStus(Students s) {
		int n=sService.deleStus(s);
		if (n>0) {
			return Result.toClient("0", "删除成功");
		}
		return Result.toClient("1", "删除失败");
	}
	//修改
		@RequestMapping("updateStus")
		public Object updateStus(Students s) {
			int n=sService.updateStus(s);
			if (n>0) {
				return Result.toClient("0", "修改成功");
			}
			return Result.toClient("1", "修改失败");
		}
}
